home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM B4 / PD-ROM B4.iso / Entertainment / Strategy / Robots / bot 1.0.1 / Tutorial / BASIC / Suicide < prev    next >
Text File  |  1991-06-25  |  2KB  |  72 lines

  1. !
  2. ! Suicide
  3. !
  4. ! This bot looks for other bots much like Bomber, except that
  5. ! when it sees another bot, it turns on its shield and charges
  6. ! at it full tilt.
  7. !
  8.  
  9. #DATA
  10.  
  11. equ INCR 23
  12.  
  13. def scn
  14. def xx
  15. def yy
  16. def damage
  17.  
  18. #CODE BASIC
  19.  
  20.     scn = Random(360)
  21.     damage = $DAMAGE
  22.     xx = Random(200)+25
  23.     yy = Random(200)+25
  24.     
  25.     ! The following few lines in fact make up the entire body
  26.     ! of this bot's code.  Everything else is done in
  27.     ! subroutines.
  28.     
  29. :Loop
  30.     If (damage <> $DAMAGE) Then Gosub Moveaway
  31.     scn = scn + INCR
  32.     Scan Angle scn
  33.     If ($FOUND == 0) Then Goto Loop
  34.     
  35.     Gosub Attack
  36.     Gosub Moveaway
  37.     Goto Loop
  38.     
  39.     
  40. ! In order to move at a given angle (here, the angle to the
  41. ! enemy bot), set velocity to (cos(angle), sin(angle)).
  42.  
  43. :Attack
  44.     Velocity Cos($ANGLE), Sin($ANGLE)
  45.     Shield ON                   ! To reduce the expected damage
  46. :ALoop
  47.     If ($XVEL <> 0) Then Goto ALoop ! After a collision, a bot
  48.     If ($YVEL <> 0) Then Goto ALoop ! automatically tries to
  49.                                     ! decelerate to (0,0)
  50.                                     ! velocity
  51.     Shield OFF
  52.   Return
  53.  
  54. ! The following subroutine is a bit different than the previous
  55. ! movement routines.  Instead of moving *to* a point in the
  56. ! arena, the bot moves *toward* a point for 20 ticks.  This
  57. ! risks smashing into walls (as the bot doesn't slow down), but
  58. ! it's easier to write than the other routine, and the bot
  59. ! won't completely choke if its treads are destroyed (as Bomber
  60. ! will -- it goes into an infinite loop trying to move to the
  61. ! specified point when the bot can no longer move at all).
  62.  
  63. :Moveaway
  64.     Velocity (xx-$XLOC)*10, (yy-$YLOC)*10
  65.     Wait 20                 ! Move for 20 ticks
  66.     Velocity 0, 0
  67.     damage = $DAMAGE
  68.     xx = Random(200)+25     ! Compute the new target point
  69.     yy = Random(200)+25
  70.   Return
  71.  
  72. #END